package ee.example.final_work

import android.content.Context
import android.view.ViewGroup
import android.widget.ImageView
import androidx.recyclerview.widget.RecyclerView
import com.bumptech.glide.Glide
import com.youth.banner.adapter.BannerAdapter

/**
 * @ClassName: RoundedBannerAdapter
 * @Description: banner 适配器
 * @Author: Nicholas.hzf
 * @Date: 2022/9/27 00:06 Created
 */
class RoundedBannerAdapter(context: Context,urls: MutableList<String>) : BannerAdapter<String, RoundedBannerAdapter.BannerViewHolder>(urls) {

    var context: Context? = null
    init {
        this.context = context
    }

    fun onCreateHolder(parent: ViewGroup?, viewType: Int): BannerViewHolder {
        val imageView = ImageView(parent!!.context).apply {
            layoutParams = ViewGroup.LayoutParams(
                ViewGroup.LayoutParams.MATCH_PARENT,
                ViewGroup.LayoutParams.MATCH_PARENT
            )
            scaleType = ImageView.ScaleType.CENTER_CROP
        }
        return BannerViewHolder(imageView)
    }

    fun onBindView(holder: BannerViewHolder?, data: String?, position: Int, size: Int) {
        Glide.with(context!!).load(data).into( holder?.imageView!!)
        data?.let {
//            holder?.imageView?.setImageResource(it)
        }
    }

    class BannerViewHolder(var imageView: ImageView) :
        RecyclerView.ViewHolder(imageView)
}